package com.atguigu.srb.servicesms.controller;

import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.servicesms.pojo.Message;
import com.atguigu.srb.servicesms.service.SmsService;
import com.atguigu.srb.servicesms.service.impl.SmsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * ClassName: SmsController
 * Package: com.atguigu.srb.servicesms.controller
 * Description:
 *
 * @Author 王晓龙
 * @Create 2023/3/29 20:41
 * @Version 1.0
 */
@Api(tags = "短信发送模块")
@RestController
@RequestMapping("/api/sms")
//@CrossOrigin
public class SmsController {
    @Resource
    SmsService smsService;

    @ApiOperation("发送消息")
    //type:发送的类型 mobile:发送消息的手机号码
    @PostMapping("/sendSms")
    public Result sendSms(
            @RequestBody Message message
            ){
        String msg = smsService.sendSms(message);
        if (StringUtils.isNotEmpty(msg)){
            return Result.error().message(msg);
        }
        return Result.ok().message("短信发送成功");
    }
}